package com.wesley.zookeeper;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;

/**
 * @author:wesley
 */
public class MyLockService {

    private MyAbstractLock abstractLock = new MyAbstractLock();

    private ZooKeeper zk = null;

    private String ipAddrss = "192.168.56.132:2181";

    private int session_time = 100000;


    public void doService(MyDoTemplate template) throws KeeperException, InterruptedException {

        zk = abstractLock.connect(ipAddrss,session_time);

        MyDistributedLock lock = new MyDistributedLock(zk);
        MyLockWatch watch = new MyLockWatch(lock,template);

        lock.setMyLockWatch(watch);
        lock.createRootNode();

        if(lock.getLock()){
            watch.doSomething();
            lock.unLock();
        }
    }



}
